package org.misty.practices.string;

import org.misty.util.Address;

import java.lang.reflect.InvocationTargetException;

public class StringTestE {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchFieldException {
        var a = "a";
        var b = "b";

        var loader = StringTestE.class.getClassLoader();
        var loadClass = ClassLoader.class.getDeclaredMethod("loadClass", String.class, boolean.class);
        loadClass.setAccessible(true);
        var resolveClass = ClassLoader.class.getDeclaredMethod("resolveClass", Class.class);
        resolveClass.setAccessible(true);

        Class<?> klass = (Class<?>) loadClass.invoke(loader, "org.misty.practices.string.LoadBySelf", false); // 加载Class，不链接
        System.out.println("After loadClass");

        resolveClass.invoke(loader, klass); // 链接
        System.out.println("After resolveClass");

        var obj = klass.getConstructor().newInstance(); // 初始化
        var method = klass.getDeclaredMethod("call");

        var c = a + b;
        System.out.println(Address.of(c));
        System.out.println(Address.of(c.intern()));


        method.invoke(obj);

        /*var c = a + b;
        System.out.println(Address.of(c));
        System.out.println(Address.of(c.intern()));*/
    }
}
